package com.googlecode.droidjni;

import android.app.*;
import android.content.Intent;

import static com.googlecode.droidjni.util.*;

public class TraceService extends IntentService {

    public static final String NOTIFICATION = "com.googlecode.droidjni.broadcast";

    static {
/*      util.timestamp("loadLibrary"); */
        System.loadLibrary("service"); /* best time seen ~1397 microseconds */
/*      util.timestamp("loadLibrary"); */
    }


    public TraceService() {
        super("TraceService");
        trace("TraceService()");
    }

    public int onStartCommand(Intent intent, int flags, int startId) {
    /*  trace("onStartCommand " + intent + " flags=" + flags + " startId=" + startId +
              " pid=" + android.os.Process.myPid() + " tid=" + Thread.currentThread().getId()); */
        return Service.START_STICKY;
    }

    public void onCreate() {
        trace("");
        super.onCreate();
        create();
    }

    public void onDestroy() {
        trace("");
        destroy();
        super.onDestroy();
    }

    protected void onHandleIntent(Intent intent) {
        trace("onHandleIntent " + intent);
        Intent i = new Intent(NOTIFICATION);
        intent.putExtra("foo", "bar");
        sendBroadcast(i);
    }

    private native void create();
    private native void destroy();

}